<?php

namespace App\Admin\Controllers\Agent;

use App\model\agent\Agent;
use App\model\agent\AgentYuyue;
use App\model\Workshop;
use Encore\Admin\Controllers\AdminController;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Show;

class AgentYuyueController extends AdminController
{
    /**
     * Title for current resource.
     *
     * @var string
     */
    protected $title = '预约列表';

    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        $grid = new Grid(new AgentYuyue);
        $grid->model()->orderBy('id','desc');
        $grid->column('id', __('Id'));
        $grid->column('name', __('姓名'));
        $grid->column('mobile', __('手机号'));
        $grid->column('time', __('预约时间'));
        $grid->column('workshop_id', __('厂房标题'))->display(function($value){
            return Workshop::find($value)->title ?? '';
        });
        $grid->column('agent_id', __('经纪人'))->display(function($value){
            return Agent::find($value)->name ?? '';
        });
        $grid->column('created_at', __('时间'));
        $grid->filter(function (Grid\Filter $filter){
            $filter->disableIdFilter();
            $filter->equal('name','姓名');
            $filter->equal('mobile','手机号');
            $filter->equal('time','预约时间');
        });
        $grid->actions(function(Grid\Displayers\Actions $actions){
            $actions->disableEdit();
        });
        return $grid;
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     * @return Show
     */
    protected function detail($id)
    {
        $show = new Show(AgentYuyue::findOrFail($id));

        $show->field('id', __('Id'));
        $show->field('name', __('Name'));
        $show->field('mobile', __('Mobile'));
        $show->field('time', __('Time'));
        $show->field('workshop_id', __('Workshop id'));
        $show->field('created_at', __('Created at'));
        $show->field('updated_at', __('Updated at'));

        return $show;
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        $form = new Form(new AgentYuyue);

        $form->text('name', __('Name'));
        $form->mobile('mobile', __('Mobile'));
        $form->text('time', __('Time'));
        $form->number('workshop_id', __('Workshop id'));

        return $form;
    }
}
